<template>
  <div class="container-login">
    <el-card>
      <img src="../../assets/logo_index.png" alt />
      <el-form :model="loginForm" :rules="loginRoules" status-icon ref="loginForm">
        <el-form-item prop="mobile">
          <el-input v-model="loginForm.mobile" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-input style="width:240px;" v-model="loginForm.code" placeholder="请输入验证码"></el-input>
          <el-button style="margin-left:7px">发送验证码</el-button>
        </el-form-item>
        <el-form-item>
          <el-checkbox type="primary" :value="true">我已阅读并同意条款</el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width:100%" @click="login()">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
           
<script>
export default {
  name: "login-page",
  data() {
    //   声明自定义校验函数
    const checkMobile = (rule, value, callback) => {
      if (!/^1[3-9]\d{9}$/.test(value))
        return callback(new Error("手机号输入不正确"));
      callback();
    };
    return {
      loginForm: {
        mobile: "",
        code: ""
      },
      loginRoules: {
        mobile: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { validator: checkMobile, trigger: "blur" }
        ],
        code: [
          { required: true, message: "请输入验证码", trigger: "blur" },
          { len: 6, message: "请输6位验证码", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    login() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
        }
      });
    }
  }
};
</script>
<style scoped lang='less'>
.container-login {
  width: 100%;
  height: 100%;
  background: url(../../assets/login_bg.jpg) no-repeat center / cover;
  position: absolute;
  left: 0;
  top: 0;
  .el-card {
    width: 400px;
    height: 350px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    img {
      width: 200px;
      display: block;
      margin: 0 auto 20px;
    }
  }
}
</style>